package com.softwinner.bt;

import com.softwinner.bt.policy.BTManager;
import com.softwinner.bt.util.BTConfig;
import com.softwinner.bt.util.BTLog;
import com.softwinner.bt.util.Command;
import com.softwinner.bt.util.Utils;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.PowerManager;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class CallDialog extends BaseActivity {
    private ImageView handupButton = null;
    private TextView nameText;
    private TextView numText = null;
    private String phoneName = null;
    private String phoneNum = null;

    public static boolean isCall = false;
    
    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.bt_call);
        isCall=true;
        Bundle localBundle = getIntent().getExtras();
        this.phoneNum = localBundle.getString("phoneNum");
        try {
        	this.phoneName = getName(this.phoneNum);
		} catch (Exception e) {}
        this.nameText = ((TextView) findViewById(R.id.bt_call_name));
        this.nameText.setText(this.phoneName);
        this.numText = ((TextView) findViewById(R.id.bt_call_num));
        this.numText.setText(this.phoneNum);
        this.handupButton = ((ImageView) findViewById(R.id.bt_call_handup));
        this.handupButton.setOnClickListener(this);
    }

	@Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.bt_call_handup:
            mBTManager.sendCommand(Command.SEND_HANG_UP);
            finish();
            break;

        default:
            break;
        }
    }

	@Override
	protected void phoneStateChanged(String action) {
		// TODO Auto-generated method stub
		if(action.equals(Utils.ACTION_PHONE_INCALL) || action.equals(Utils.ACTION_HANGUP)){
			finish();
		}
	}
	
	@Override
	protected void onDestroy(){
		// TODO Auto-generated method stub
		BTLog.i(this.getClass(), "onDestroy()");
		isCall = false;
		super.onDestroy();
	}
}
